#include "errorlist.h"
#include "errorlabel.h"
#include <QVBoxLayout>

ErrorList::ErrorList(QWidget *parent) :
  QScrollArea(parent)
{
  layout = new QVBoxLayout();
  layout->setSizeConstraint(QLayout::SetMinAndMaxSize);

  QWidget* list = new QWidget();
  list->setMinimumWidth(width());
  list->setLayout(layout);

  setWidget(list);
}

void ErrorList::AddError(const QString &file, const QString &mess, int line) {
  ErrorLabel* label = new ErrorLabel(file, mess, line);
  layout->addWidget(label);
  layout->setAlignment(label, Qt::AlignTop);
  connect(label, SIGNAL(clicked(QString,int)), this,
          SIGNAL(error_clicked(QString,int)));
}

void ErrorList::clean() {
  QLayoutItem *item;
  while((item = layout->takeAt(0))) {
      if (item->widget()) {
          delete item->widget();
      }
      delete item;
  }
}
